<?php
/**
 * 模块详情查看脚本
 * 用于查看特定模块的接口详情
 */

// 检查参数
if ($argc < 2) {
    echo "用法: php module_detail.php <module_name>\n";
    echo "例如: php module_detail.php customer\n";
    exit(1);
}

$moduleName = $argv[1];

// 读取API映射文件
$apiMapping = json_decode(file_get_contents('api_mapping.json'), true);

if (!isset($apiMapping[$moduleName])) {
    echo "错误: 模块 '{$moduleName}' 不存在\n";
    exit(1);
}

$moduleInfo = $apiMapping[$moduleName];

echo "========================================\n";
echo "模块详情: {$moduleInfo['name']} ({$moduleName})\n";
echo "========================================\n";
echo "接口数量: " . count($moduleInfo['endpoints']) . "\n\n";

echo "接口列表:\n";
echo str_repeat("-", 80) . "\n";
printf("%-10s %-30s %-30s\n", "方法", "路径", "描述");
echo str_repeat("-", 80) . "\n";

foreach ($moduleInfo['endpoints'] as $endpoint) {
    printf("%-10s %-30s %-30s\n", 
        $endpoint['http_method'], 
        $endpoint['src'], 
        $endpoint['title'] . ' ' . $endpoint['name']
    );
}

echo str_repeat("-", 80) . "\n";

// 统计HTTP方法分布
$methodStats = [];
foreach ($moduleInfo['endpoints'] as $endpoint) {
    $method = $endpoint['http_method'];
    if (!isset($methodStats[$method])) {
        $methodStats[$method] = 0;
    }
    $methodStats[$method]++;
}

echo "\nHTTP方法分布:\n";
foreach ($methodStats as $method => $count) {
    echo "  {$method}: {$count} 个接口\n";
}